/**
 * 
 */
package metalink.admin;

import model.admin.LibraryMo;
import vo.BookBorrowVo;

import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Sony
 * 
 */
public class IssueBook extends ActionSupport {
	String borrower_type, view = "";

	int borrower_id = 0, book_id = 0;
	LibraryMo mo = new LibraryMo();

	public String execute() {
		if (!view.equals("view")) {
			if (book_id == 0 || borrower_id == 0) {
				addActionError("Please fill in all the details");
				return SUCCESS;
			}
		
			System.out.println("issuing book with id : "+book_id+" and borrower "+borrower_id);
			try {
				BookBorrowVo bv = new BookBorrowVo();
				bv.setBook_id(book_id);
				bv.setBorrower_id(borrower_id);

				if (borrower_type.equals("student")) {
					bv.setBorrower_type(borrower_type);
				} else if (borrower_type.equals("staff")) {
					bv.setBorrower_type(borrower_type);
				}

				mo = new LibraryMo();
				mo.AddDetails(bv);
			} catch (Exception ex) {
				addActionError(ex.getMessage()+"");
				return SUCCESS;
			}
			addActionError("Issued..!!");
		}
		
		return SUCCESS;
	}

	public String getView() {
		return view;
	}

	public void setView(String view) {
		this.view = view;
	}

	public String getBorrower_type() {
		return borrower_type;
	}

	public int getBorrower_id() {
		return borrower_id;
	}

	public int getBook_id() {
		return book_id;
	}

	public void setBorrower_type(String borrower_type) {
		this.borrower_type = borrower_type;
	}

	public void setBorrower_id(int borrower_id) {
		this.borrower_id = borrower_id;
	}

	public void setBook_id(int book_id) {
		this.book_id = book_id;
	}

}
